package com.example.movie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.movie.mapper.MovieMapper;
import com.example.movie.domain.Movie;
import com.example.movie.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MovieServiceImpl extends ServiceImpl<MovieMapper, Movie> implements MovieService {

    @Autowired
    MovieMapper movieMapper;

    @Override
    public Page<Movie> getMovie(String movieName,Long currentPage,Long pageSize) {
        Page<Movie> page = new Page<>();
        page.setCurrent(currentPage);
        page.setSize(pageSize);
        QueryWrapper<Movie> qw = new QueryWrapper<>();
        qw.like("m_name", movieName);
        qw.orderByDesc("m_year");
        Page<Movie> result = this.page(page, qw);

        return result;
    }

    @Override
    public List<Movie> getRecentMoviesIds() {
        QueryWrapper<Movie> qw = new QueryWrapper<>();
        qw.orderByDesc("m_time");
        qw.last(" limit 300");
        List<Movie> movies = movieMapper.selectList(qw);
        return movies;
    }

}
